﻿/* 
 * author: www.cnblogs.com/luminji
 * date  : 2011/11/18
 */
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Luminji.Core.reflect;

namespace Luminji.Core.UnitTest.reflect
{
    [TestClass]
    public class ReflectHelperTest
    {
        [TestMethod]
        public void TestMethodObjectCopy()
        {
            SampleParent parent = new SampleParent(33);
            //parent.Age = 33;
            parent.Name = "luminji";
            SampleChild child = new SampleChild();
            SampleOther other = new SampleOther();
            ReflectHelper.SetPropertiesFromOtherObject(parent, child);
            Assert.AreEqual(child.Age, 33);
            Assert.AreEqual(child.Name, "luminji");
            Assert.AreEqual(child.Code, null);
            ReflectHelper.SetPropertiesFromOtherObject(parent, other);
            Assert.AreEqual(other.Age, 33);
            Assert.AreEqual(other.Name, "luminji");
            Assert.AreEqual(other.EmployeeYears, 0);
            Assert.AreEqual(other.ID, null);
        }

        class SampleParent
        {
            internal protected SampleParent()
            {
            }
            internal protected SampleParent(int age)
            {
                Age = age;
            }
            public string Name { get; set; }
            private int Age { get; set; }   
        }

        private class SampleChild: SampleParent
        {
            public int Age { get; set; }
            public string Code { get; set; }   
        }

        private class SampleOther
        {
            public string Name { get; set; }
            public int Age { get; set; }
            public string ID { get; set; }
            public int EmployeeYears { get; set; }   
            
        }
    }
}
